var app = getApp(); //获取应用实例
const quote = app.globalData.quote;
const mta = quote.mta;
const api = quote.api;
const tools = quote.tools;
const path = quote.paths;

Page({
    data: {
        path: path,
        Money: '',
        title: '分享红包'
    },
    onLoad: function(options) {
        // 生命周期函数--监听页面加载
        mta.Page.init();

        console.log('options', options);
        var Money = options.Money;
        var title = options.title;
        this.setData({
            Money,
            title
        })
    },
    onReady: function() {
        // 生命周期函数--监听页面初次渲染完成
        var that = this;

        if (that.data.Money || that.data.title) {
            return
        }

        that.ReceiveRedEnvelopes();

    },
    onShow: function() {
        // 生命周期函数--监听页面显示
    },
    onHide: function() {
        // 生命周期函数--监听页面隐藏
    },
    onUnload: function() {
        // 生命周期函数--监听页面卸载
    },
    onPullDownRefresh: function() {
        // 页面相关事件处理函数--监听用户下拉动作
    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
    },
    onShareAppMessage: function() {
        // 用户点击右上角分享
        return {
            title: 'title', // 分享标题
            desc: 'desc', // 分享描述
            path: 'path' // 分享路径
        }
    },
    ReceiveRedEnvelopes: function(params) {
        var that = this;

        var dataDic = {
            OpenId: app.globalData.openId
        }
        api.methodReceiveRedEnvelopes({
            dataDic: dataDic,
            complete: function(res) {
                console.log('获取随机红包金额', res);
                if (res.data.code != 0) {
                    wx.showModal({
                        title: '温馨提示',
                        content: res.data.msg,
                        showCancel: false,
                        success: function(res) {
                            if (res.confirm) {
                                console.log('用户点击确定')
                            }
                        }
                    })
                    return
                }
                that.setData({
                    Money: res.data.data.RedAmount
                })
            }
        })
    },
    gotoMyAccount: function(params) {
        var that = this;

        app.aldstat.sendEvent('分享红包-点击去看看');
        mta.Event.stat("scorePreview_clickgotoMyAccount", {});

        wx.navigateTo({
            url: '/' + path.myAccount
        })
    }
})